#include "easylog.h"

EasyLog *gLog(){
    static EasyLog *gsLog ;
    if (gsLog == nullptr)
        gsLog = new EasyLog("d://peerconection.txt");
    return gsLog;
}

EasyLog::EasyLog(std::string path):
    mFile(nullptr)
{
    mFile = fopen(path.c_str(),"w+");
    if(mFile == nullptr){
        qDebug()<<"easylog";
    }
}

int EasyLog::Log(std::string data)
{
    std::unique_lock<std::mutex> mutex(mMux);
    if((mFile == nullptr)){
        return -1;
    }
    int ret = fwrite(data.c_str(),data.size(),1,mFile);
    fwrite("\r\n",2,1,mFile);

    fflush(mFile);
    return ret;
};

